#!/bin/sh

Title="SecuLution"
Description="SecuLution product presentation"
Author="SecuLution GmbH"
page=home
page_files="$page"_files
filename=${page}.htm
backup=$filename.bak
tmpfilename=$filename.tmp
home="home"
home_lang="home_en"

if grep -q '<!-- processed -->' $filename; then
	if test -e $backup; then
		echo $0 using backup $backup
		cp $backup $filename
	else
		echo Backup $backup existiert nicht
		exit 1
	fi
else
	echo creating backup file
	. ./createbackup.sh
fi

ersetzen() {
	nummer=`cat $filename| grep -ni $tag|cut -d ':' -f1`
	nummer=`expr $nummer - $davor`
	weiter=`expr $nummer + $anzahl`
	gesamt=`wc -l $filename|cut -d' ' -f1`
	cat $filename | sed -n "1,$nummer p" > $tmpfilename
	echo -n $einsetzen >> $tmpfilename
	cat $filename| sed -n "$weiter,$gesamt p" >> $tmpfilename
	rm $filename
	mv $tmpfilename $filename
}

loeschen() {
	cat $filename | grep -v "$tag" > $tmpfilename
	rm $filename
	mv $tmpfilename $filename
}

# Google Analytics Block entfernen.
start=1
tag=googleanaly
anzahl=10
davor=2
einsetzen=""
ersetzen

# Video 1 einbauen
tag=Video1
anzahl=4
davor=2
einsetzen='<div id="video1"><iframe class="youtube-player" type="text/html" width="640" height="385" src="http://www.youtube.com/embed/XZagHLGmfqE?enablejsapi=1" frameborder="0" allowfullscreen="1">
</iframe></div>'
ersetzen

# Video 2 einbauen
tag=Video2
anzahl=4
davor=2
einsetzen='<div id="video2"><iframe class="youtube-player" type="text/html" width="550" height="430" src="http://www.youtube.com/embed/_btBNRUOFlU?enablejsapi=1" frameborder="0" allowfullscreen="1">
</iframe></div>'
ersetzen

# die Links 
# href="http://strut.io/editor/preview_export/css/themes/default-reset.css">
# und 
# href="http://strut.io/editor/preview_export/reveal/css/theme/default.css" 
# sollen aus der htm rausgehalten werden. Die Dateien wurden dazu vorher mal runtergeladen (wget)
# mit gunzip entpackt und unter ./CSS abgelegt
# jetzt müssen wir diese Links also nur noch in der htm Datei ersetzen (sed unten)


mv $filename $tmpfilename

cat $tmpfilename | \
	sed -f sed-command-files/control-youtube.sed | \
	sed -f sed-command-files/remove-comments.sed | \
	sed -f sed-command-files/set-author.sed | \
	sed -f sed-command-files/relocate-default-reset.sed | \
	sed -f sed-command-files/relocate-default.sed | \
	sed -f sed-command-files/remove-overview.sed | \
	sed -f sed-command-files/remove-absolute-path.sed | \
	sed -f sed-command-files/anwenderbericht.sed | \
	sed -f sed-command-files/navigation-hint.sed | \
	sed -f sed-command-files/mikogo.sed | \
	sed -f sed-command-files/remove-google-analytics.sed |\
	sed "s/Deck Title/$Title/" | \
	sed "s/\"description\" content=\"TODO\"/\"description\" content=\"$Description\"/" | \
	sed "s@./${page}_files/aw.html@http://www.seculution.de/versions/aw.txt@" | \
	sed "s@./${page}_files/agent.html@http://www.seculution.de/versions/agent.txt@" | \
	sed "s@./${page}_files/server.html@http://www.seculution.de/versions/server.txt@" | \
	sed "s@./${page}_files/uninstaller.html@http://www.seculution.de/versions/uninstaller.txt@" | \
	sed "s@./${page}_files/rcm.html@http://www.seculution.de/versions/rcm.txt@" | \
	sed "s/http:\/\/www.4ss.de\/$filename//g" | \
	sed "s/http:\/\/www.echte-sicherheit.de\/$filename//g" | \
	sed "s/<img src=\".\/${page}_files\/right.png\">/<a href=\"javascript:impress().next();\"><img src=\".\/${page}_files\/right.png\"><\/a>/" | \
	sed "s/<img src=\".\/${page}_files\/_right.png\">/<a href=\"javascript:impress().next();\"><img src=\".\/${page}_files\/_right.png\"><\/a>/" | \
	sed "s/<img src=\".\/${page}_files\/sl400x420.png\">/<a href=\".\/$filename#\/step-5\"> <img src=\".\/${page}_files\/sl400x420.png\"><\/a>/g" | \
	sed "s/<img src=\".\/${page}_files\/sl80x85.png\">/<a href=\".\/$filename#\/step-5\"> <img src=\".\/${page}_files\/sl80x85.png\"><\/a>/g" | \
	sed "s/<img src=\".\/${page}_files\/flag_uk.png\">/  <a href=\".\/${home_lang}.htm\">       <img src=\".\/i\/flag_uk.png\"><\/a>/g" | \
	sed "s/<img src=\".\/${page}_files\/_flag_uk.png\">/  <a href=\".\/${home_lang}.htm\">       <img src=\".\/i\/_flag_uk.png\"><\/a>/g" | \
	sed "s/${page}_files/support_files/g" | \
	cat > $filename

echo "<!-- processed -->" >> $filename
rm $tmpfilename

# Strut.io web bugs löschen
tag=strut.io
loeschen

exit 0

	
	
	


#	sed "s@</head>@<script async=\"\" src=\"./support_files/controlyoutube.js\"></script></head>@" | \ 		# control_youtube.sed
#	sed 's/^<!.*-->$//' | \																					# remove-comments.sed
#	sed "s/\"author\" content=\"TODO\"/\"author\" content=\"SecuLution GmbH\"/" | \							# set-author.sed
#	sed "s@http://strut.io/editor/preview_export/css/themes/default-reset.css@./CSS/default-reset.css@" | \	# relocate-default-reset.sed
#	sed "s@http://strut.io/editor/preview_export/reveal/css/theme/default.css@./CSS/default.css@" | \		# relocate-default.sed
#	sed "s@<div id=\"overview\" class=\"step future\" .*<\/div>@@" | \										# remove-overview.sed

#	sed "s/http:\/\/www.4ss.de\/relative//g" | \															# remove-absolute-path.sed
#	sed "s/http:\/\/www.4ss.de/./" | \
#	sed "s/http:\/\/www.echte-sicherheit.de\/relative//g" | \
#	sed "s/http:\/\/www.echte-sicherheit.de/./" | \

# mikogo.sed
#	sed 's/<font color="#000000" face="League Gothic">Live Support erhalten<\/font>/<!-- Mikogo Session Login Start -->\n<!-- <form method="POST" action="http:\/\/go.mikogo.com" style="display: inline;"> -->\n <form method="POST" action="http:\/\/go.mikogo.com" >\n <input type="hidden" name="sl" id="sl" value="de">\n <input type="hidden" name="css" id="css" value="">\n <input type="hidden" name="sid" id="sid" value="975-218-294">\n <input type="hidden" name="sn" id="sn" value="i">\n <input type="submit" value="Live Demo beitreten" id="btnSubmit" name="btnSubmit">\n <input type="hidden"id="cm" name="cm" value="2" checked="checked">\n <\/form>\n <form method="POST" action="http:\/\/go.mikogo.com" >\n <input type="hidden" name="sl" id="sl" value="de">\n <input type="hidden" name="css" id="css" value="">\n <input type="hidden" name="sid" id="sid" value="134-791-826">\n <input type="hidden" name="sn" id="sn" value="s">\n <input type="submit" value="Support erhalten" id="btnSubmit" name="btnSubmit">\n <input type="hidden"id="cm" name="cm" value="1" checked="checked">\n <\/form>\n	<!-- Mikogo Session Login End -->/' | \

#	sed "s/anwenderbericht.pdf\">/anwenderbericht.pdf\" target=\"_blank\">/" |\								# anwenderbericht.sed
#	sed "s/Use a spacebar or arrow keys to navigate/zum Navigieren LEERTASTE oder Pfeiltasten/g" | \		# navigation-hint.sed





# Hier kommen Beispiele, die schon mal funktioniert haben, aber im Moment nicht wichtig sind

	sed 's/<font color="#000000" face="League Gothic">Live Support erhalten</font>/<!-- Mikogo Session Login Start -->\n<!-- <form method="POST" action="http:\/\/go.mikogo.com" style="display: inline;"> -->\n <form method="POST" action="http:\/\/go.mikogo.com" >\n <input type="hidden" name="sl" id="sl" value="de">\n <input type="hidden" name="css" id="css" value="">\n <input type="hidden" name="sid" id="sid" value="975-218-294">\n <input type="hidden" name="sn" id="sn" value="i">\n <input type="submit" value="Live Demo beitreten" id="btnSubmit" name="btnSubmit">\n <input type="hidden"id="cm" name="cm" value="2" checked="checked">\n <\/form>\n <form method="POST" action="http:\/\/go.mikogo.com" >\n <input type="hidden" name="sl" id="sl" value="de">\n <input type="hidden" name="css" id="css" value="">\n <input type="hidden" name="sid" id="sid" value="134-791-826">\n <input type="hidden" name="sn" id="sn" value="s">\n <input type="submit" value="Support erhalten" id="btnSubmit" name="btnSubmit">\n <input type="hidden"id="cm" name="cm" value="1" checked="checked">\n <\/form>\n <!-- Mikogo Session Login End -->/' | \
	sed 's/<img src=".\/index2_files\/sl400x420.png">/<a href="http:\/\/www.4ss.de\/$filename#\/step-3"> <img src=".\/index2_files\/sl400x420.png"><\/a>/g' | \
	sed 's/http:\/\/www.4ss.de\/$filename//g' | \
	cat > $filename

	# sed 's/<img src=".\/index2_files\/sl400x420.png">/<img src=".\/index2_files\/sl400x420.png">\n<a href="http:\/\/www.4ss.de\/$filename#\/step-3" class="img-link">/g' | \
